import { formatTime, calculateDays } from '@/utils/utils.js'
export default {
  data() {
    return {
      oldTax: '',
      appointTax: '',
      overdueDays: 0,
      taxCount: 0,
      startDate: '',
      endDate: '',
      resultShow: false,
      multiple: 1
    }
  },
  watch: {

  },
  methods: {

    //起算日期
    startDateChange(e) {
      this.startDate = e.detail.value
    },

    //截止日期
    endDateChange(e) {
      this.endDate = e.detail.value
    },

    //重置
    resetBtn() {
      this.resultShow = false
      this.oldTax = ''
      this.appointTax = ''
    },

    //计算
    countBtn() {
      if (this.oldTax == '') {
        this.$tools.msg('请填写金额')
        return
      }
      if (this.appointTax == '') {
        this.$tools.msg('请填写约定利率')
        return
      }
      this.resultShow = true
      this.overdueDays = calculateDays(this.startDate, this.endDate)
      const a = this.appointTax / 100
      const price = (this.oldTax * a * this.overdueDays * this.multiple) / 365
      this.taxCount = price.toFixed(2)
    }
  },
  onLoad(options) {
    //获取当前时间
    const date = new Date()
    this.startDate = formatTime(date, 'Y-M-D')
    this.endDate = formatTime(date, 'Y-M-D')
  }
}